console.log(process.argv);
try {
  const fs = require("fs");
  const originName = process.argv[2];
  const outputName = process.argv[3];
  const file = fs.readFileSync("./public/json/" + originName, "utf-8");
  const jsonObject = JSON.parse(file);
  console.log(Object.prototype.toString.call(jsonObject));
  // console.log(jsonObject.slice(0, 10));
  let newJson = {};

  newJson.contents = jsonObject.rows.map((row) => {
    const rowObj = {};
    row.forEach((value, index) => {
      rowObj[jsonObject.columns[index].name] = value;
    });
    return rowObj;
  });

  fs.writeFileSync(
    "./public/json/" + outputName,
    outputName.split(".")[0] + "(" + JSON.stringify(newJson) + ")",
    "utf-8"
  );
} catch (e) {
  console.log(e);
}
